<html>
<head><meta charset="utf-8"><title>Transmuting &amp;Struct from/to &amp;[u8] · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html">Transmuting &amp;Struct from/to &amp;[u8]</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232889769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232889769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232889769">(Apr 02 2021 at 11:44)</a>:</h4>
<p>Hello. I’m making a library that transmutes (or dereferences pointers after casting) <code>&amp;SomeCustomStruct</code> from or to <code>&amp;[u8]</code>, for reading or writing binary files. I’d like to confirm the invariants that need to be maintained to avoid UB. For "from bytes" I have: 1. all bit patterns must be valid for struct fields (so no <code>bool</code>, enum, etc) 2. <code>align_of() == 1</code>. For "to bytes": no padding. Does this sound right?</p>



<a name="232890064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232890064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232890064">(Apr 02 2021 at 11:48)</a>:</h4>
<p>You should check out the <code>zerocopy</code> crate, which has traits for this</p>



<a name="232890237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232890237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232890237">(Apr 02 2021 at 11:51)</a>:</h4>
<p>Quoting from there:</p>
<blockquote>
<p>If a type has the following properties, then it is safe to implement <code>FromBytes</code> for that type:</p>
<ul>
<li>If the type is a struct:<ul>
<li>It must have a defined representation (<code>repr(C)</code>, <code>repr(transparent)</code>, or <code>repr(packed)</code>)</li>
<li>All of its fields must implement <code>FromBytes</code></li>
</ul>
</li>
<li>If the type is an enum:<ul>
<li>It must be a C-like enum (meaning that all variants have no fields)</li>
<li>It must have a defined representation (<code>repr</code>s <code>C</code>, <code>u8</code>, <code>u16</code>, <code>u32</code>, <code>u64</code>, <code>usize</code>, <code>i8</code>, <code>i16</code>, <code>i32</code>, <code>i64</code>, or <code>isize</code>).</li>
<li>The maximum number of discriminants must be used (so that every possible bit pattern is a valid one). Be very careful when using the <code>C</code>, <code>usize</code>, or <code>isize</code> representations, as their size is platform-dependent.</li>
</ul>
</li>
</ul>
<p>If a type has the following properties, then it is safe to implement <code>AsBytes</code> for that type</p>
<ul>
<li>If the type is a struct:<ul>
<li>It must have a defined representation (<code>repr(C)</code>, <code>repr(transparent)</code>, or <code>repr(packed)</code>).</li>
<li>All of its fields must be <code>AsBytes</code></li>
<li>Its layout must have no inter-field padding. This is always true for <code>repr(transparent)</code> and <code>repr(packed)</code>. For <code>repr(C)</code>, see the layout algorithm described in the <a href="https://doc.rust-lang.org/reference/type-layout.html">Rust Reference</a>.</li>
</ul>
</li>
<li>If the type is an enum:<ul>
<li>It must be a C-like enum (meaning that all variants have no fields)</li>
<li>It must have a defined representation (<code>repr</code>s <code>C</code>, <code>u8</code>, <code>u16</code>, <code>u32</code>, <code>u64</code>, <code>usize</code>, <code>i8</code>, <code>i16</code>, <code>i32</code>, <code>i64</code>, or <code>isize</code>).</li>
</ul>
</li>
</ul>
</blockquote>



<a name="232890308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232890308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232890308">(Apr 02 2021 at 11:52)</a>:</h4>
<p>I’ve looked at <code>zerocopy</code> and a few other crates, but I’d like slightly different APIs. (Also,<code>zerocopy</code> does not have a public issue tracker and my email to the author some time ago never got a response)</p>



<a name="232890564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232890564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232890564">(Apr 02 2021 at 11:55)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> What are you quoting from? <a href="https://docs.rs/zerocopy/0.4.0/zerocopy/trait.FromBytes.html#safety">https://docs.rs/zerocopy/0.4.0/zerocopy/trait.FromBytes.html#safety</a> looks like a different version of the same since it doesn’t list <code>repr</code> as arequirement for structs</p>



<a name="232890634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232890634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232890634">(Apr 02 2021 at 11:56)</a>:</h4>
<p>That quote was from the 0.2.1 docs</p>



<a name="232890738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232890738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232890738">(Apr 02 2021 at 11:58)</a>:</h4>
<p>I think it is fair to say that repr(Rust) structs are always unsafe to transmute like this until the safe-transmute stuff lands</p>



<a name="232890898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232890898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232890898">(Apr 02 2021 at 12:00)</a>:</h4>
<p>Oh, the 0.4.0 documentation has an interesting rationale for why it's okay to view padding bytes using <code>FromBytes</code></p>



<a name="232891099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232891099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232891099">(Apr 02 2021 at 12:02)</a>:</h4>
<p>it cites <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/174">UCG#174</a> to say that padding bytes are safe to observe because they don't have validity constraints, but I would have expected uninitialized padding bytes to present a problem</p>



<a name="232891570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232891570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232891570">(Apr 02 2021 at 12:08)</a>:</h4>
<p>I’m ok with limiting to <code>repr(C)</code>, but different versions of <code>zerocopy</code> saying different things is why I’d like confirmation either from authoritative docs (<a href="https://doc.rust-lang.org/std/mem/fn.transmute.html">https://doc.rust-lang.org/std/mem/fn.transmute.html</a> doesn’t say much) or at least from this group along the lines "yes, this subset of transmutes are sound"</p>



<a name="232891635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232891635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232891635">(Apr 02 2021 at 12:08)</a>:</h4>
<p>Even if it’s a very conservative subset</p>



<a name="232893151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232893151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232893151">(Apr 02 2021 at 12:26)</a>:</h4>
<p>I don't think the zerocopy docs disagree with your characterization. The semantic property required is "all bit patterns valid and no alignment" for <code>FromBytes</code> and "no padding" for <code>AsBytes</code>; the list of constraints in the zerocopy docs ensure how you can achieve those properties in a struct definition</p>



<a name="232893446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232893446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232893446">(Apr 02 2021 at 12:30)</a>:</h4>
<p>There are additional issues around types with lifetimes, which is why the zerocopy docs are conservative and don't permit any kind of pointers</p>



<a name="232895856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232895856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232895856">(Apr 02 2021 at 13:00)</a>:</h4>
<p>I <code>repr(C)</code> struct with <code>align_of() == 1</code> can’t have padding, right?</p>



<a name="232895879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232895879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232895879">(Apr 02 2021 at 13:00)</a>:</h4>
<p>Since all fields also have to have <code>align_of() == 1</code></p>



<a name="232895969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232895969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232895969">(Apr 02 2021 at 13:01)</a>:</h4>
<p>(Padding between fields. Within field is checked when looking at that field’s type)</p>



<a name="232896254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232896254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232896254">(Apr 02 2021 at 13:04)</a>:</h4>
<p>Is the<br>
<a href="https://docs.rs/bytemuck/1.5.1/bytemuck/fn.bytes_of.html">https://docs.rs/bytemuck/1.5.1/bytemuck/fn.bytes_of.html</a> function closer to what you intended?</p>



<a name="232896858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232896858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232896858">(Apr 02 2021 at 13:11)</a>:</h4>
<p><a href="https://docs.rs/bytemuck/1.5.1/bytemuck/trait.Pod.html#safety">https://docs.rs/bytemuck/1.5.1/bytemuck/trait.Pod.html#safety</a> would be the relevant part but yes, that too</p>



<a name="232898119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232898119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232898119">(Apr 02 2021 at 13:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219747">Simon Sapin</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232890308">said</a>:</p>
<blockquote>
<p>(Also,<code>zerocopy</code> does not have a public issue tracker and my email to the author some time ago never got a response)</p>
</blockquote>
<p>cc <span class="user-mention" data-user-id="132362">@Joshua Liebow-Feeser</span></p>



<a name="232902362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232902362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232902362">(Apr 02 2021 at 14:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219747">Simon Sapin</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232895856">said</a>:</p>
<blockquote>
<p>I <code>repr(C)</code> struct with <code>align_of() == 1</code> can’t have padding, right?</p>
</blockquote>
<p>It can't have padding, but it can have niches; you should check for the niche attributes or blacklist <code>Box</code>, <code>NonNull</code> etc</p>



<a name="232922649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232922649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232922649">(Apr 02 2021 at 16:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232890898">said</a>:</p>
<blockquote>
<p>Oh, the 0.4.0 documentation has an interesting rationale for why it's okay to view padding bytes using <code>FromBytes</code></p>
</blockquote>
<p>padding is easy in <code>FromBytes</code>, so I am confused what you are concerned about here?</p>



<a name="232922729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232922729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232922729">(Apr 02 2021 at 16:53)</a>:</h4>
<p>We might want to have "guaranteed 0 padding" some day (<a href="https://github.com/rust-lang/rust/issues/70230">#70230</a>), but that's most likely going to require opt-in to avoid compatibility issues</p>



<a name="232922973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232922973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232922973">(Apr 02 2021 at 16:55)</a>:</h4>
<blockquote>
<p>For "from bytes" I have: 1. all bit patterns must be valid for struct fields (so no bool, enum, etc) 2. align_of() == 1. For "to bytes": no padding. Does this sound right?</p>
</blockquote>
<p>for to_bytes, the precise requirement is "all bit patterns that are valid for the struct must be fully initialized". this is using a slightly different notion of "bit pattern" than you: a "bit pattern" in the Rust Abstract Machine consists of bits that are either 0, 1, or U(ninitialized).<br>
So padding in the struct is a problem, but so is <code>MaybeUninit</code>. The conservative version of this would be: no padding, no <code>union</code>.</p>



<a name="232922985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232922985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232922985">(Apr 02 2021 at 16:55)</a>:</h4>
<p><span class="user-mention" data-user-id="219747">@Simon Sapin</span> ^</p>



<a name="232923164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923164">(Apr 02 2021 at 16:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232922649">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232890898">said</a>:</p>
<blockquote>
<p>Oh, the 0.4.0 documentation has an interesting rationale for why it's okay to view padding bytes using <code>FromBytes</code></p>
</blockquote>
<p>padding is easy in <code>FromBytes</code>, so I am confused what you are concerned about here?</p>
</blockquote>
<p>My mistake, I confused it with <code>AsBytes</code></p>



<a name="232923309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923309">(Apr 02 2021 at 16:58)</a>:</h4>
<blockquote>
<p>This is using a slightly different notion of "bit pattern" than you: a "bit pattern" in the Rust Abstract Machine consists of bits that are either 0, 1, or U(ninitialized).</p>
</blockquote>
<p>Maybe we should call that "trit pattern"? :D</p>



<a name="232923373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923373">(Apr 02 2021 at 16:58)</a>:</h4>
<p>Furthermore, there is some <em>really subtle</em> nasty issues around transmuting pointers to integers. On the one hand I know of no way to resolve this other than saying that the transmute is UB. On the other hand that probably breaks <em>so much</em> code. But this might be why some of the existing crates rule out pointers.</p>



<a name="232923406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923406">(Apr 02 2021 at 16:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232923309">said</a>:</p>
<blockquote>
<blockquote>
<p>This is using a slightly different notion of "bit pattern" than you: a "bit pattern" in the Rust Abstract Machine consists of bits that are either 0, 1, or U(ninitialized).</p>
</blockquote>
<p>Maybe we should call that "trit pattern"? :D</p>
</blockquote>
<p>:P<br>
I like to call them "abstract bits" or "abits" for short.</p>



<a name="232923432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923432">(Apr 02 2021 at 16:58)</a>:</h4>
<p>The input <code>&amp;[u8]</code> is assumed initialized, yes</p>



<a name="232923443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923443">(Apr 02 2021 at 16:59)</a>:</h4>
<p>because when you make it fully precise, there's not three of them, there's infinitely many</p>



<a name="232923489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923489">(Apr 02 2021 at 16:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219747">Simon Sapin</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232923432">said</a>:</p>
<blockquote>
<p>The input <code>&amp;[u8]</code> is assumed initialized, yes</p>
</blockquote>
<p>I was talking about the other direction. transmuting <code>&amp;MaybeUninit&lt;u8&gt;</code> to <code>&amp;[u8]</code> is <em>not</em> sound, even though there is no padding.</p>



<a name="232923690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923690">(Apr 02 2021 at 17:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232923373">said</a>:</p>
<blockquote>
<p>Furthermore, there is some <em>really subtle</em> nasty issues around transmuting pointers to integers. On the one hand I know of no way to resolve this other than saying that the transmute is UB. On the other hand that probably breaks <em>so much</em> code. But this might be why some of the existing crates rule out pointers.</p>
</blockquote>
<p>see <a href="#narrow/stream/216762-project-safe-transmute/topic/Transmuting.20betwen.20references.20.2F.20raw.20pointers.20.2F.20integers">this discussion</a> for more details</p>



<a name="232923800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232923800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232923800">(Apr 02 2021 at 17:01)</a>:</h4>
<p>Does that mean that transmuting to <code>MaybeUninit&lt;[u8]&gt;</code> would be okay in ~all situations?</p>



<a name="232924244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232924244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232924244">(Apr 02 2021 at 17:04)</a>:</h4>
<p>Or equivalently: <code>&amp;A -&gt; &amp;MaybeUninit&lt;A&gt;</code> is always safe, <code>&amp;MaybeUninit&lt;A&gt; -&gt; &amp;MaybeUninit&lt;B&gt;</code> is safe if <code>A</code> and <code>B</code> have the same size and alignment</p>



<a name="232924299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232924299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232924299">(Apr 02 2021 at 17:04)</a>:</h4>
<p>those almost seem like standard library functions</p>



<a name="232924429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232924429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232924429">(Apr 02 2021 at 17:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232923800">said</a>:</p>
<blockquote>
<p>Does that mean that transmuting to <code>MaybeUninit&lt;[u8]&gt;</code> would be okay in ~all situations?</p>
</blockquote>
<p>yes</p>



<a name="232924449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232924449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232924449">(Apr 02 2021 at 17:05)</a>:</h4>
<p>that is the intention of <code>MaybeUninit</code></p>



<a name="232924538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232924538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232924538">(Apr 02 2021 at 17:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232924244">said</a>:</p>
<blockquote>
<p>Or equivalently: <code>&amp;A -&gt; &amp;MaybeUninit&lt;A&gt;</code> is always safe, <code>&amp;MaybeUninit&lt;A&gt; -&gt; &amp;MaybeUninit&lt;B&gt;</code> is safe if <code>A</code> and <code>B</code> have the same size and alignment</p>
</blockquote>
<p>even if <code>B</code>'s alignment is weaker than <code>A</code>'s, this is still okay</p>



<a name="232924858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232924858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232924858">(Apr 02 2021 at 17:08)</a>:</h4>
<p>For parsing binary files I think a minimal useful subset is: "byte-transmutable" types are <code>u8</code>, arrays of byte-transmutable items, and <code>#[repr(C)]</code> of byte-transmutable fields</p>



<a name="232924902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232924902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232924902">(Apr 02 2021 at 17:09)</a>:</h4>
<p>(then for example <code>u32</code> is handled with a wrapper struct for <code>[u8; 4]</code>)</p>



<a name="232925344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232925344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232925344">(Apr 02 2021 at 17:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219747">Simon Sapin</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232924858">said</a>:</p>
<blockquote>
<p>For parsing binary files I think a minimal useful subset is: "byte-transmutable" types are <code>u8</code>, arrays of byte-transmutable items, and <code>#[repr(C)]</code> of byte-transmutable fields</p>
</blockquote>
<p>that family of types is sound to transmute to and from <code>&amp;[u8]</code>, yes</p>



<a name="232926596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232926596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232926596">(Apr 02 2021 at 17:21)</a>:</h4>
<p>That’s the minimal thing, but I’d still like to document accurate invariants for my library’s <code>unsafe trait</code></p>



<a name="232927064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232927064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232927064">(Apr 02 2021 at 17:25)</a>:</h4>
<p>actually I take that back, it's not in general sound -- it just doesn't cause immediate UB</p>



<a name="232927089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232927089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232927089">(Apr 02 2021 at 17:25)</a>:</h4>
<p>but of course there might be safety invariants that are violated</p>



<a name="232927395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232927395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232927395">(Apr 02 2021 at 17:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219747">Simon Sapin</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232926596">said</a>:</p>
<blockquote>
<p>That’s the minimal thing, but I’d still like to document accurate invariants for my library’s <code>unsafe trait</code></p>
</blockquote>
<p>yes, see my comments above for that, in particular <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232922973">this</a> but also <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D/near/232923690">this caveat</a>.</p>



<a name="232929184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232929184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232929184">(Apr 02 2021 at 17:40)</a>:</h4>
<p>oops, bytemuck has pointers listed as pod</p>



<a name="232929193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232929193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232929193">(Apr 02 2021 at 17:40)</a>:</h4>
<p>rip</p>



<a name="232937778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting%20%26Struct%20from/to%20%26%5Bu8%5D/near/232937778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Transmuting.20.26Struct.20from.2Fto.20.26.5Bu8.5D.html#232937778">(Apr 02 2021 at 18:54)</a>:</h4>
<p>yeah I really hope we can find a better solution than making ptr-to-int transmute UB^^</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>